﻿// Copyright (C) 2009 Choonghwan Lee (linjus.lee@gmail.com)
//
// This file is part of amanda.
//
// amanda is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// amanda is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with amanda. If not, see <http://www.gnu.org/licenses/>.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace manager
{
	/// <summary>
	/// Interaction logic for Wizard1Library.xaml
	/// </summary>
	public partial class Wizard1Library : PageFunction<WizardResult>
	{
		private WizardData data;

		public Wizard1Library(WizardData data)
		{
			InitializeComponent();

			this.data = data;

			this.FillDescription();
			this.listBoxLibrary.ItemsSource = Configuration.Libraries;
		}

		private void listBoxLibrary_SelectionChanged(object sender, SelectionChangedEventArgs e)
		{
			LibraryInfo library = (LibraryInfo)this.listBoxLibrary.SelectedItem;
			this.textLibraryInfo.Text =
				"Library '" + library.Name + "':\r\n" +
				"  foobar2000 Playlist: " + library.PlaylistName + "\r\n" +
				"  Playlist's root folder: " + library.PlaylistRootPath + "\r\n" +
				"  Device: " + library.DeviceName + "\r\n" +
				"  Device's folder: " + library.DeviceRootPath;

			this.data.LibraryInfo = library;
			this.buttonNext.IsEnabled = true;
		}

		private void FillDescription()
		{
			this.textDescription.Text =
				"Choose a library you want to synchornize from the below list. " +
				"If you want to add a library, create an XML file under " + Configuration.LibraryDirectory + ". " +
				"That XML file should conform to the XSD file in the same directory.";
		}

		private void buttonNext_Click(object sender, RoutedEventArgs e)
		{
			PageFunction<WizardResult> page = new Wizard2Device(this.data);
			page.Return += (object s, ReturnEventArgs<WizardResult> ev) => this.OnReturn(ev);
			this.NavigationService.Navigate(page);
		}
	}
}
